from django.db.models.manager import Manager


class SerTable:
    def __init__(self):
        self.table = Manager

    def traversal(self):
        """
        遍历
        :return:
        """
        return self.table.all()

    def select(self, *args, **kwargs):
        """
        查询数据库
        :param args:
        :param kwargs:
        :return:
        """
        select_dict = kwargs.get("select_dict")
        return self.table.filter(**select_dict)

    def page(self, *args, **kwargs):
        """
        分页器
        :param args:
        :param kwargs:
        :return:
        """
        query = kwargs.get("query")
        page = int(kwargs.get("page"))
        limit = int(kwargs.get("limit"))
        content = [info for info in query]
        start = (page - 1) * limit
        end = page * limit
        return content[start:end]
